#!/usr/bin/env python
# coding=utf-8
"""WTFM"""

def int_to_romain(a):
    Symbols = [
        {
            'capacity': 1000,
            'name': 'M'
        }, {
            'capacity': 500,
            'name': 'D'
        }, {
            'capacity': 100,
            'name': 'C'
        }, {
            'capacity': 50,
            'name': 'L'
        }, {
            'capacity': 10,
            'name': 'X'
        }, {
            'capacity': 5,
            'name': 'V'
        }, {
            'capacity': 1,
            'name': 'I'
        }
    ]
    result = ''
    b = a
    for i, syb in enumerate(Symbols):
        syb_num = b // syb['capacity']
        if syb_num > 0:
            result += syb['name'] * syb_num
            b = b - syb_num * syb['capacity']

        # 这个符号可以进行减1的符号
        sub_syb_index = (i // 2 + 1) * 2
        if sub_syb_index < len(Symbols):
            sub_syb = Symbols[sub_syb_index]
            syb_num = (b + sub_syb['capacity']) // syb['capacity']
            if syb_num > 0:
                result += sub_syb['name'] + syb['name']
                b = b - syb['capacity'] + sub_syb['capacity']

        i = i + 1
        if b == 0:
            break

    return result


if __name__ == '__main__':
    print(int_to_romain(987))
    # for i in range(50):
    #     print(int_to_romain(i))
